<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Node Annotations</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Node Annotations' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../services.html">Services</a></li><li><a href="index.html">syntax</a></li><li><a href="index.html#2">Chapter 2: The Parse Tree</a></li><li><b>Node Annotations</b></li></ul></div>
<p class="purpose">Attaching general-purpose data to nodes in the syntax tree.</p>

<ul class="toc"><li><a href="2-na.html#SP1">&#167;1. Annotation types</a></li><li><a href="2-na.html#SP3">&#167;3. Annotations</a></li><li><a href="2-na.html#SP6">&#167;6. Reading annotations</a></li><li><a href="2-na.html#SP8">&#167;8. Writing annotations</a></li><li><a href="2-na.html#SP10">&#167;10. Setters and getters</a></li><li><a href="2-na.html#SP12">&#167;12. Copying annotations</a></li><li><a href="2-na.html#SP13">&#167;13. Annotation permissions</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Annotation types.</b>The parse tree annotations are miscellaneous, and many are needed only at a
few unusual nodes. Rather than have the structure grow large, we store
annotations, allowing each node in principle to have an arbitrary set (though
see below).
</p>

<p class="commentary">The following annotations used by the syntax module.
</p>

<pre class="definitions code-font"><span class="definition-keyword">enum</span> <span class="constant-syntax">heading_level_ANNOT</span><span class="plain-syntax"> </span><span class="identifier-syntax">from</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax"> </span><span class="comment-syntax"> int: for HEADING nodes, a hierarchical level, 0 (highest) to 9 (lowest)</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">language_element_ANNOT</span><span class="plain-syntax"> </span><span class="comment-syntax"> int: this node is not really a sentence, but a language definition Use</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">suppress_heading_dependencies_ANNOT</span><span class="plain-syntax"> </span><span class="comment-syntax"> int: ignore extension dependencies on this heading node</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">implied_heading_ANNOT</span><span class="plain-syntax"> </span><span class="comment-syntax"> int: set only for the heading of implied inclusions</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">dialogue_level_ANNOT</span><span class="plain-syntax"> </span><span class="comment-syntax"> int: for DIALOGUE_CUE and DIALOGUE_LINE nodes, indendation level</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">dialogue_during_text_w1_ANNOT</span><span class="plain-syntax"> </span><span class="comment-syntax"> </span><span class="extract"><span class="extract-syntax">int</span></span><span class="comment-syntax">: first word of during scene wording</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">dialogue_during_text_w2_ANNOT</span><span class="plain-syntax"> </span><span class="comment-syntax"> </span><span class="extract"><span class="extract-syntax">int</span></span><span class="comment-syntax">: first word of during scene wording</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">MAX_ANNOT_NUMBER</span><span class="plain-syntax"> (</span><span class="identifier-syntax">NO_DEFINED_ANNOT_VALUES</span><span class="plain-syntax">+1)</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::begin</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Annotations::begin</span></span>:<br/>Syntax Module - <a href="1-sm.html#SP3">&#167;3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP2" class="function-link"><span class="function-syntax">Annotations::declare_type</span></a><span class="plain-syntax">(</span><span class="constant-syntax">heading_level_ANNOT</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><a href="2-na.html#SP1" class="function-link"><span class="function-syntax">Annotations::write_heading_level_ANNOT</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP2" class="function-link"><span class="function-syntax">Annotations::declare_type</span></a><span class="plain-syntax">(</span><span class="constant-syntax">language_element_ANNOT</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><a href="2-na.html#SP1" class="function-link"><span class="function-syntax">Annotations::write_language_element_ANNOT</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP2" class="function-link"><span class="function-syntax">Annotations::declare_type</span></a><span class="plain-syntax">(</span><span class="constant-syntax">suppress_heading_dependencies_ANNOT</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><a href="2-na.html#SP1" class="function-link"><span class="function-syntax">Annotations::write_suppress_heading_dependencies_ANNOT</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP2" class="function-link"><span class="function-syntax">Annotations::declare_type</span></a><span class="plain-syntax">(</span><span class="constant-syntax">implied_heading_ANNOT</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><a href="2-na.html#SP1" class="function-link"><span class="function-syntax">Annotations::write_implied_heading_ANNOT</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP2" class="function-link"><span class="function-syntax">Annotations::declare_type</span></a><span class="plain-syntax">(</span><span class="constant-syntax">dialogue_level_ANNOT</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><a href="2-na.html#SP1" class="function-link"><span class="function-syntax">Annotations::write_dialogue_level_ANNOT</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP2" class="function-link"><span class="function-syntax">Annotations::declare_type</span></a><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="constant-syntax">dialogue_during_text_w1_ANNOT</span><span class="plain-syntax">, </span><a href="2-na.html#SP1" class="function-link"><span class="function-syntax">Annotations::write_dialogue_during_text_ANNOT</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP2" class="function-link"><span class="function-syntax">Annotations::declare_type</span></a><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="constant-syntax">dialogue_during_text_w2_ANNOT</span><span class="plain-syntax">, </span><a href="2-na.html#SP1" class="function-link"><span class="function-syntax">Annotations::do_not_write_dialogue_during_text_ANNOT</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::write_heading_level_ANNOT</span><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">p</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-na.html#SP7" class="function-link"><span class="function-syntax">Annotations::read_int</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">, </span><span class="constant-syntax">heading_level_ANNOT</span><span class="plain-syntax">) &gt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" {heading %d}"</span><span class="plain-syntax">, </span><a href="2-na.html#SP7" class="function-link"><span class="function-syntax">Annotations::read_int</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">, </span><span class="constant-syntax">heading_level_ANNOT</span><span class="plain-syntax">));</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::write_language_element_ANNOT</span><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">p</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-na.html#SP7" class="function-link"><span class="function-syntax">Annotations::read_int</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">, </span><span class="constant-syntax">language_element_ANNOT</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" {language element}"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::write_suppress_heading_dependencies_ANNOT</span><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">p</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-na.html#SP7" class="function-link"><span class="function-syntax">Annotations::read_int</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">, </span><span class="constant-syntax">suppress_heading_dependencies_ANNOT</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" {suppress dependencies}"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::write_implied_heading_ANNOT</span><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">p</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-na.html#SP7" class="function-link"><span class="function-syntax">Annotations::read_int</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">, </span><span class="constant-syntax">implied_heading_ANNOT</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" {implied}"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::write_dialogue_level_ANNOT</span><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">p</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-na.html#SP7" class="function-link"><span class="function-syntax">Annotations::read_int</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">, </span><span class="constant-syntax">dialogue_level_ANNOT</span><span class="plain-syntax">) &gt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" {level %d}"</span><span class="plain-syntax">, </span><a href="2-na.html#SP7" class="function-link"><span class="function-syntax">Annotations::read_int</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">, </span><span class="constant-syntax">dialogue_level_ANNOT</span><span class="plain-syntax">));</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::write_dialogue_during_text_ANNOT</span><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">p</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">w1</span><span class="plain-syntax"> = </span><a href="2-na.html#SP7" class="function-link"><span class="function-syntax">Annotations::read_int</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">, </span><span class="constant-syntax">dialogue_during_text_w1_ANNOT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">w2</span><span class="plain-syntax"> = </span><a href="2-na.html#SP7" class="function-link"><span class="function-syntax">Annotations::read_int</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">p</span><span class="plain-syntax">, </span><span class="constant-syntax">dialogue_during_text_w2_ANNOT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">w1</span><span class="plain-syntax">, </span><span class="identifier-syntax">w2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">w1</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" {dialogue during text: %W}"</span><span class="plain-syntax">, </span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::do_not_write_dialogue_during_text_ANNOT</span><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">p</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>Annotations are identified by type, which are enumerated constants, and
these must be declared before use.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">parse_node_annotation_type</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">void</span><span class="plain-syntax"> (*</span><span class="identifier-syntax">writer_function</span><span class="plain-syntax">)(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *, </span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">p</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">parse_node_annotation_type</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">known_annotation_types_started</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">parse_node_annotation_type</span><span class="plain-syntax"> *</span><span class="identifier-syntax">known_annotation_types</span><span class="plain-syntax">[</span><span class="constant-syntax">MAX_ANNOT_NUMBER</span><span class="plain-syntax">];</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::declare_type</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">Annotations::declare_type</span></span>:<br/><a href="2-na.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="reserved-syntax">void</span><span class="plain-syntax"> (*</span><span class="identifier-syntax">f</span><span class="plain-syntax">)(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *, </span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *)) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">id</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">id</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">MAX_ANNOT_NUMBER</span><span class="plain-syntax">)) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"annot out of range"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"no logging function"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">known_annotation_types_started</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="constant-syntax">MAX_ANNOT_NUMBER</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="identifier-syntax">known_annotation_types</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">known_annotation_types_started</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">known_annotation_types</span><span class="plain-syntax">[</span><span class="identifier-syntax">id</span><span class="plain-syntax">]) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"annot declared twice"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">known_annotation_types</span><span class="plain-syntax">[</span><span class="identifier-syntax">id</span><span class="plain-syntax">] = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node_annotation_type</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">known_annotation_types</span><span class="plain-syntax">[</span><span class="identifier-syntax">id</span><span class="plain-syntax">]-&gt;</span><span class="element-syntax">writer_function</span><span class="plain-syntax"> = </span><span class="identifier-syntax">f</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::write_annotations</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">Annotations::write_annotations</span></span>:<br/>Parse Nodes - <a href="2-pn.html#SP18">&#167;18</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">PN</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pna</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">PN</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pna</span><span class="plain-syntax">=</span><span class="identifier-syntax">PN</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax">=</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_id</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">id</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">id</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">MAX_ANNOT_NUMBER</span><span class="plain-syntax">)) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"annot out of range"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">known_annotation_types</span><span class="plain-syntax">[</span><span class="identifier-syntax">id</span><span class="plain-syntax">] == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"undeclared annot"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">known_annotation_types</span><span class="plain-syntax">[</span><span class="identifier-syntax">id</span><span class="plain-syntax">]-&gt;</span><span class="element-syntax">writer_function</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                (*(</span><span class="identifier-syntax">known_annotation_types</span><span class="plain-syntax">[</span><span class="identifier-syntax">id</span><span class="plain-syntax">]-&gt;</span><span class="element-syntax">writer_function</span><span class="plain-syntax">))(</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="identifier-syntax">PN</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>The structure parse_node_annotation_type is private to this section.</li></ul>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. Annotations.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">annotation_id</span><span class="plain-syntax">; </span><span class="comment-syntax"> one of the </span><span class="extract"><span class="extract-syntax">*_ANNOT</span></span><span class="comment-syntax"> values</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">annotation_integer</span><span class="plain-syntax">; </span><span class="comment-syntax"> if this is an integer annotation, or ...</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">annotation_pointer</span><span class="plain-syntax">; </span><span class="comment-syntax"> ... if it holds an object</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">next_annotation</span><span class="plain-syntax">;</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure parse_node_annotation is accessed in 2/tv and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>A new annotation is like a blank luggage ticket, waiting to be filled out
and attached to some suitcase. All is has is its ID:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax"> *</span><span class="function-syntax">Annotations::new</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">Annotations::new</span></span>:<br/><a href="2-na.html#SP8">&#167;8</a>, <a href="2-na.html#SP9">&#167;9</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">id</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">id</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">MAX_ANNOT_NUMBER</span><span class="plain-syntax">)) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"annot out of range"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">known_annotation_types</span><span class="plain-syntax">[</span><span class="identifier-syntax">id</span><span class="plain-syntax">] == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"undeclared annot"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pna</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">id</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_integer</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_pointer</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL_GENERAL_POINTER</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">pna</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>Each node has a linked list of <a href="2-na.html#SP3" class="internal">parse_node_annotation</a> objects, but for
speed and to reduce memory usage we implement this by hand rather than using
the linked list class from <a href="../foundation/index.html" class="internal">foundation</a>. A node <span class="extract"><span class="extract-syntax">N</span></span> has a list <span class="extract"><span class="extract-syntax">N-&gt;annotations</span></span>,
which points to its first <a href="2-na.html#SP3" class="internal">parse_node_annotation</a>, or is <span class="extract"><span class="extract-syntax">NULL</span></span> if the node
is unannotated.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::clear</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">Annotations::clear</span></span>:<br/>Parse Nodes - <a href="2-pn.html#SP2">&#167;2</a>, <a href="2-pn.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">PN</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">PN</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. Reading annotations.</b>Though there will be many such lists, each one will always be short (worst case
about 5), so a more efficient search algorithm would not pay its overheads.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::node_has</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">Annotations::node_has</span></span>:<br/><a href="2-na.html#SP10">&#167;10</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">PN</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pna</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">PN</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pna</span><span class="plain-syntax">=</span><span class="identifier-syntax">PN</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax">=</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_id</span><span class="plain-syntax"> == </span><span class="identifier-syntax">id</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>Reading annotations is similar. We need two variant forms: one for reading
integer-valued annotations (which is most of them, as it happens) and the
other for reading pointers to objects.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::read_int</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">Annotations::read_int</span></span>:<br/><a href="2-na.html#SP1">&#167;1</a><br/>Syntax Trees - <a href="2-st.html#SP4_1">&#167;4.1</a>, <a href="2-st.html#SP16">&#167;16</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">PN</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pna</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">PN</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pna</span><span class="plain-syntax">=</span><span class="identifier-syntax">PN</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax">=</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_id</span><span class="plain-syntax"> == </span><span class="identifier-syntax">id</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_integer</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::read_object</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">Annotations::read_object</span></span>:<br/><a href="2-na.html#SP10">&#167;10</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">PN</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pna</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">PN</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pna</span><span class="plain-syntax">=</span><span class="identifier-syntax">PN</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax">=</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_id</span><span class="plain-syntax"> == </span><span class="identifier-syntax">id</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_pointer</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL_GENERAL_POINTER</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. Writing annotations.</b>Note that any second or subsequent annotation with the same ID as an existing
one (on the same node) overwrites it, but this is not an error.
</p>

<p class="commentary">Again, integers first:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::write_int</span><button class="popup" onclick="togglePopup('usagePopup9')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup9">Usage of <span class="code-font"><span class="function-syntax">Annotations::write_int</span></span>:<br/>Sentences - <a href="3-snt.html#SP7_1">&#167;7.1</a>, <a href="3-snt.html#SP7_6">&#167;7.6</a>, <a href="3-snt.html#SP7_7_3">&#167;7.7.3</a>, <a href="3-snt.html#SP7_7_6">&#167;7.7.6</a>, <a href="3-snt.html#SP7_7_8_1">&#167;7.7.8.1</a>, <a href="3-snt.html#SP7_7_8_2">&#167;7.7.8.2</a>, <a href="3-snt.html#SP7_7_8_3">&#167;7.7.8.3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">PN</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">newpna</span><span class="plain-syntax">, *</span><span class="identifier-syntax">pna</span><span class="plain-syntax">, *</span><span class="identifier-syntax">final</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">PN</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"annotated null PN"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pna</span><span class="plain-syntax">=</span><span class="identifier-syntax">PN</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax">=</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_id</span><span class="plain-syntax"> == </span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="comment-syntax"> an annotation with this id exists already: overwrite it</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_integer</span><span class="plain-syntax"> = </span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">final</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pna</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="comment-syntax"> no annotation with this id exists: create a new one and add to end of node's list</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">newpna</span><span class="plain-syntax"> = </span><a href="2-na.html#SP4" class="function-link"><span class="function-syntax">Annotations::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">); </span><span class="identifier-syntax">newpna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_integer</span><span class="plain-syntax"> = </span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">final</span><span class="plain-syntax">) </span><span class="identifier-syntax">final</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax"> = </span><span class="identifier-syntax">newpna</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">PN</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax"> = </span><span class="identifier-syntax">newpna</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. </b>And now objects:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::write_object</span><button class="popup" onclick="togglePopup('usagePopup10')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup10">Usage of <span class="code-font"><span class="function-syntax">Annotations::write_object</span></span>:<br/><a href="2-na.html#SP10">&#167;10</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">PN</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">data</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">PN</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"annotated null PN"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">newpna</span><span class="plain-syntax">, *</span><span class="identifier-syntax">pna</span><span class="plain-syntax">, *</span><span class="identifier-syntax">final</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pna</span><span class="plain-syntax">=</span><span class="identifier-syntax">PN</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax">=</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_id</span><span class="plain-syntax"> == </span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="comment-syntax"> an annotation with this id exists already: overwrite it</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_pointer</span><span class="plain-syntax"> = </span><span class="identifier-syntax">data</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">final</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pna</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="comment-syntax"> no annotation with this id exists: create a new one and add to end of node's list</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">newpna</span><span class="plain-syntax"> = </span><a href="2-na.html#SP4" class="function-link"><span class="function-syntax">Annotations::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">); </span><span class="identifier-syntax">newpna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_pointer</span><span class="plain-syntax"> = </span><span class="identifier-syntax">data</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">final</span><span class="plain-syntax">) </span><span class="identifier-syntax">final</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax"> = </span><span class="identifier-syntax">newpna</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">PN</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax"> = </span><span class="identifier-syntax">newpna</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. Setters and getters.</b>It's a nuisance to use <a href="2-na.html#SP7" class="internal">Annotations::read_object</a> and <a href="2-na.html#SP9" class="internal">Annotations::write_object</a>
directly because of the need to wrap and unwrap the objects into <span class="extract"><span class="extract-syntax">general_pointers</span></span>s,
so we use macros to make convenient get and set functions.
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="identifier-syntax">MAKE_ANNOTATION_FUNCTIONS</span><span class="plain-syntax">(</span><span class="identifier-syntax">annotation_name</span><span class="plain-syntax">, </span><span class="identifier-syntax">pointer_type</span><span class="plain-syntax">)</span>
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="identifier-syntax">Node::set_</span><span class="plain-syntax">##</span><span class="identifier-syntax">annotation_name</span><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pn</span><span class="plain-syntax">, </span><span class="identifier-syntax">pointer_type</span><span class="plain-syntax"> *</span><span class="identifier-syntax">bp</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP9" class="function-link"><span class="function-syntax">Annotations::write_object</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">pn</span><span class="plain-syntax">, </span><span class="identifier-syntax">annotation_name</span><span class="plain-syntax">##</span><span class="identifier-syntax">_ANNOT</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">STORE_POINTER_</span><span class="plain-syntax">##</span><span class="identifier-syntax">pointer_type</span><span class="plain-syntax">(</span><span class="identifier-syntax">bp</span><span class="plain-syntax">));</span>
<span class="plain-syntax">}</span>
<span class="identifier-syntax">pointer_type</span><span class="plain-syntax"> *</span><span class="identifier-syntax">Node::get_</span><span class="plain-syntax">##</span><span class="identifier-syntax">annotation_name</span><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pn</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pointer_type</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pt</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-na.html#SP6" class="function-link"><span class="function-syntax">Annotations::node_has</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">pn</span><span class="plain-syntax">, </span><span class="identifier-syntax">annotation_name</span><span class="plain-syntax">##</span><span class="identifier-syntax">_ANNOT</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">pt</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RETRIEVE_POINTER_</span><span class="plain-syntax">##</span><span class="identifier-syntax">pointer_type</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><a href="2-na.html#SP7" class="function-link"><span class="function-syntax">Annotations::read_object</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">pn</span><span class="plain-syntax">, </span><span class="identifier-syntax">annotation_name</span><span class="plain-syntax">##</span><span class="identifier-syntax">_ANNOT</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">pt</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. </b>Access routines will be needed for some of these, and the following
constructs them:
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="identifier-syntax">DECLARE_ANNOTATION_FUNCTIONS</span><span class="plain-syntax">(</span><span class="identifier-syntax">annotation_name</span><span class="plain-syntax">, </span><span class="identifier-syntax">pointer_type</span><span class="plain-syntax">)</span>
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="identifier-syntax">Node::set_</span><span class="plain-syntax">##</span><span class="identifier-syntax">annotation_name</span><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pn</span><span class="plain-syntax">, </span><span class="identifier-syntax">pointer_type</span><span class="plain-syntax"> *</span><span class="identifier-syntax">bp</span><span class="plain-syntax">);</span>
<span class="identifier-syntax">pointer_type</span><span class="plain-syntax"> *</span><span class="identifier-syntax">Node::get_</span><span class="plain-syntax">##</span><span class="identifier-syntax">annotation_name</span><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pn</span><span class="plain-syntax">);</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. Copying annotations.</b>For the most part, an annotation can be copied directly from one node to
another: if it's an integer, or a pointer to an immutable sort of object.
But this sort of shallow copy won't always suffice, and so we allow for
a callback function to deep-copy the data inside the annotation if it
wants to.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::copy</span><button class="popup" onclick="togglePopup('usagePopup11')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup11">Usage of <span class="code-font"><span class="function-syntax">Annotations::copy</span></span>:<br/>Parse Nodes - <a href="2-pn.html#SP9">&#167;9</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">to</span><span class="plain-syntax">, </span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">from</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">to</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pna</span><span class="plain-syntax"> = </span><span class="identifier-syntax">from</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax">, *</span><span class="identifier-syntax">latest</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">pna</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax">=</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pna_copy</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        *</span><span class="identifier-syntax">pna_copy</span><span class="plain-syntax"> = *</span><span class="identifier-syntax">pna</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        #</span><span class="identifier-syntax">ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">ANNOTATION_COPY_SYNTAX_CALLBACK</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">ANNOTATION_COPY_SYNTAX_CALLBACK</span><span class="plain-syntax">(</span><span class="identifier-syntax">pna_copy</span><span class="plain-syntax">, </span><span class="identifier-syntax">pna</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        #</span><span class="identifier-syntax">endif</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">pna_copy</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">to</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">to</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pna_copy</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">latest</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pna_copy</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">latest</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pna_copy</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. Annotation permissions.</b>As a piece of defensive coding, <a href="index.html" class="internal">syntax</a> will not allow arbitrary annotations
to be made: only annotations appropriate to the type of the node in question.
For example, attempting to give an <span class="extract"><span class="extract-syntax">heading_level_ANNOT</span></span> to a <span class="extract"><span class="extract-syntax">SENTENCE_NT</span></span>
node will throw an internal error &mdash; it must mean a bug in Inform.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::make_annotation_allowed_table</span><button class="popup" onclick="togglePopup('usagePopup12')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup12">Usage of <span class="code-font"><span class="function-syntax">Annotations::make_annotation_allowed_table</span></span>:<br/>Syntax Module - <a href="1-sm.html#SP3">&#167;3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP14" class="function-link"><span class="function-syntax">Annotations::allow</span></a><span class="plain-syntax">(</span><span class="constant-syntax">HEADING_NT</span><span class="plain-syntax">, </span><span class="constant-syntax">heading_level_ANNOT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP14" class="function-link"><span class="function-syntax">Annotations::allow</span></a><span class="plain-syntax">(</span><span class="constant-syntax">HEADING_NT</span><span class="plain-syntax">, </span><span class="constant-syntax">suppress_heading_dependencies_ANNOT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP14" class="function-link"><span class="function-syntax">Annotations::allow</span></a><span class="plain-syntax">(</span><span class="constant-syntax">HEADING_NT</span><span class="plain-syntax">, </span><span class="constant-syntax">implied_heading_ANNOT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP14" class="function-link"><span class="function-syntax">Annotations::allow</span></a><span class="plain-syntax">(</span><span class="constant-syntax">SENTENCE_NT</span><span class="plain-syntax">, </span><span class="constant-syntax">language_element_ANNOT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP14" class="function-link"><span class="function-syntax">Annotations::allow</span></a><span class="plain-syntax">(</span><span class="constant-syntax">DIALOGUE_CUE_NT</span><span class="plain-syntax">, </span><span class="constant-syntax">dialogue_level_ANNOT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP14" class="function-link"><span class="function-syntax">Annotations::allow</span></a><span class="plain-syntax">(</span><span class="constant-syntax">DIALOGUE_CUE_NT</span><span class="plain-syntax">, </span><span class="constant-syntax">dialogue_during_text_w1_ANNOT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP14" class="function-link"><span class="function-syntax">Annotations::allow</span></a><span class="plain-syntax">(</span><span class="constant-syntax">DIALOGUE_CUE_NT</span><span class="plain-syntax">, </span><span class="constant-syntax">dialogue_during_text_w2_ANNOT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP14" class="function-link"><span class="function-syntax">Annotations::allow</span></a><span class="plain-syntax">(</span><span class="constant-syntax">DIALOGUE_CHOICE_NT</span><span class="plain-syntax">, </span><span class="constant-syntax">dialogue_level_ANNOT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-na.html#SP14" class="function-link"><span class="function-syntax">Annotations::allow</span></a><span class="plain-syntax">(</span><span class="constant-syntax">DIALOGUE_LINE_NT</span><span class="plain-syntax">, </span><span class="constant-syntax">dialogue_level_ANNOT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    #</span><span class="identifier-syntax">ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">ANNOTATION_PERMISSIONS_SYNTAX_CALLBACK</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ANNOTATION_PERMISSIONS_SYNTAX_CALLBACK</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    #</span><span class="identifier-syntax">endif</span>
<span class="plain-syntax">    #</span><span class="identifier-syntax">ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">MORE_ANNOTATION_PERMISSIONS_SYNTAX_CALLBACK</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">MORE_ANNOTATION_PERMISSIONS_SYNTAX_CALLBACK</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    #</span><span class="identifier-syntax">endif</span>
<span class="plain-syntax">    #</span><span class="identifier-syntax">ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">EVEN_MORE_ANNOTATION_PERMISSIONS_SYNTAX_CALLBACK</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">EVEN_MORE_ANNOTATION_PERMISSIONS_SYNTAX_CALLBACK</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    #</span><span class="identifier-syntax">endif</span>
<span class="plain-syntax">    #</span><span class="identifier-syntax">ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">STILL_MORE_ANNOTATION_PERMISSIONS_SYNTAX_CALLBACK</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">STILL_MORE_ANNOTATION_PERMISSIONS_SYNTAX_CALLBACK</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    #</span><span class="identifier-syntax">endif</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. </b>The <span class="extract"><span class="extract-syntax">ANNOTATION_PERMISSIONS_SYNTAX_CALLBACK</span></span> function, if it exists, is
expected also to call the following:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">annotation_allowed</span><span class="plain-syntax">[</span><span class="identifier-syntax">NO_DEFINED_NT_VALUES</span><span class="plain-syntax">][</span><span class="constant-syntax">MAX_ANNOT_NUMBER</span><span class="plain-syntax">+1];</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::allow</span><button class="popup" onclick="togglePopup('usagePopup13')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup13">Usage of <span class="code-font"><span class="function-syntax">Annotations::allow</span></span>:<br/><a href="2-na.html#SP13">&#167;13</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">node_type_t</span><span class="plain-syntax"> </span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">annot</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">annotation_allowed</span><span class="plain-syntax">[</span><span class="identifier-syntax">t</span><span class="plain-syntax"> - </span><span class="constant-syntax">ENUMERATED_NT_BASE</span><span class="plain-syntax">][</span><span class="identifier-syntax">annot</span><span class="plain-syntax">] = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::allow_for_category</span><span class="plain-syntax">(</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">cat</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">annot</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER_ENUMERATED_NTS</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-nt.html#SP10" class="function-link"><span class="function-syntax">NodeType::category</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">) == </span><span class="identifier-syntax">cat</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><a href="2-na.html#SP14" class="function-link"><span class="function-syntax">Annotations::allow</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">annot</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>&#167;15. </b>And this allows the following. Note that nodes with the temporary <span class="extract"><span class="extract-syntax">*_MC</span></span>
types (i.e., those of an unenumerated node type) cannot be annotated.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::is_allowed</span><button class="popup" onclick="togglePopup('usagePopup14')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup14">Usage of <span class="code-font"><span class="function-syntax">Annotations::is_allowed</span></span>:<br/><a href="2-na.html#SP16">&#167;16</a><br/>Tree Verification - <a href="2-tv.html#SP4_2">&#167;4.2</a></span></button><span class="plain-syntax">(</span><span class="constant-syntax">node_type_t</span><span class="plain-syntax"> </span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">annot</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">annot</span><span class="plain-syntax"> &lt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">annot</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">MAX_ANNOT_NUMBER</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"annotation number out of range"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-nt.html#SP2" class="function-link"><span class="function-syntax">NodeType::is_enumerated</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">annotation_allowed</span><span class="plain-syntax">[</span><span class="identifier-syntax">t</span><span class="plain-syntax"> - </span><span class="constant-syntax">ENUMERATED_NT_BASE</span><span class="plain-syntax">][</span><span class="identifier-syntax">annot</span><span class="plain-syntax">];</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP16" class="paragraph-anchor"></a><b>&#167;16. </b>The following removes any annotation not currently valid for the node; this
is rarely used by Inform, but is needed when a node changes its type.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Annotations::clear_invalid</span><button class="popup" onclick="togglePopup('usagePopup15')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup15">Usage of <span class="code-font"><span class="function-syntax">Annotations::clear_invalid</span></span>:<br/>Parse Nodes - <a href="2-pn.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pn</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="constant-syntax">node_type_t</span><span class="plain-syntax"> </span><span class="identifier-syntax">nt</span><span class="plain-syntax"> = </span><a href="2-pn.html#SP5" class="function-link"><span class="function-syntax">Node::get_type</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">pn</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">pn</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (!(</span><a href="2-na.html#SP15" class="function-link"><span class="function-syntax">Annotations::is_allowed</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">nt</span><span class="plain-syntax">, </span><span class="identifier-syntax">pn</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_id</span><span class="plain-syntax">))))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">pn</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pn</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">parse_node_annotation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pna</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pn</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax">; </span><span class="identifier-syntax">pna</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (!(</span><a href="2-na.html#SP15" class="function-link"><span class="function-syntax">Annotations::is_allowed</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">nt</span><span class="plain-syntax">, </span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_id</span><span class="plain-syntax">))))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pna</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_annotation</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="2-pn.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-sm.html">1</a></li><li class="progresscurrentchapter">2</li><li class="progresssection"><a href="2-st.html">st</a></li><li class="progresssection"><a href="2-nt.html">nt</a></li><li class="progresssection"><a href="2-pn.html">pn</a></li><li class="progresscurrent">na</li><li class="progresssection"><a href="2-tv.html">tv</a></li><li class="progresssection"><a href="2-spc.html">spc</a></li><li class="progresschapter"><a href="3-snt.html">3</a></li><li class="progressnext"><a href="2-tv.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

